package com.bootcamp.javase;

import com.sun.xml.internal.ws.message.source.PayloadSourceMessage;

import java.util.Scanner;

/**
 * @program: OopCode
 * @description:
 * @author: Keyu Li
 * @create: 2021-08-27 19:01
 **/

public class twoDimensionStudents {
    public static void main(String[] args) {
        double[][] stuScores = new double[3][];
        Scanner sc = new Scanner(System.in);
        // class 1
        stuScores[0] = new double[3];
        System.out.println("3 sutdents in class 1 scores are: ");
        for (int i = 0; i < 3; i++) {
            stuScores[0][i] = sc.nextDouble();
        }
        // class 2
        stuScores[1] = new double[2];
        System.out.println("2 sutdents in class 2 scores are: ");
        for (int i = 0; i < 2; i++) {
            stuScores[1][i] = sc.nextDouble();
        }
        // class 2
        stuScores[2] = new double[5];
        System.out.println("5 sutdents in class 3 scores are: ");
        for (int i = 0; i < 5; i++) {
            stuScores[2][i] = sc.nextDouble();
        }

        System.out.println("3 classes average scores are: " +
                getAverage(stuScores[0]) + ", " +
                getAverage(stuScores[1]) + ", " +
                getAverage(stuScores[2]));

        for (int i = 0; i < 3; i++) {
            System.out.println("class " + (i + 1) + " highest & lowest score is: " +
                    getHighestScore(stuScores[i]) +", "+ getLowestScore(stuScores[i]));
        }
    }

    private static double getAverage(double[] stuScore) {
        double sum = 0.0;
        for (int i = 0; i < stuScore.length; i++) {
            sum += stuScore[i];
        }
        return sum / stuScore.length;
    }

    private static double getHighestScore(double[] stuScore) {
        double max = stuScore[0];
        for (int i = 1; i < stuScore.length; i++) {
            max = max > stuScore[i] ? max : stuScore[i];
        }
        return max;
    }

    private static double getLowestScore(double[] stuScore) {
        double min = stuScore[0];
        for (int i = 1; i < stuScore.length; i++) {
            min = min < stuScore[i] ? min : stuScore[i];
        }
        return min;
    }
}
